#include <bits/stdc++.h>
// 2024/11/08
// tag:
using namespace std;

int n, g[100001], ans;
bool vis[100001], isring[100001];

/**
 * Depth-first search function to mark visited nodes and detect rings.
 * @param x The node to start the search from.
 */
void dfs(int x)
{
    vis[x] = true;
    if (vis[g[x]])
        isring[g[x]] = true;
    else
        dfs(g[x]);
}

/**
 * Depth-first search function to mark nodes in the ring.
 * @param x The node to start the search from.
 */
void dfs2(int x)
{
    isring[x] = true;
    if (!isring[g[x]])
        dfs2(g[x]);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> g[i];

    for (int i = 1; i <= n; i++)
        if (!vis[i])
            dfs(i);

    for (int i = 1; i <= n; i++)
        if (isring[i])
            dfs2(i);

    for (int i = 1; i <= n; i++)
        ans += isring[i];
    cout << ans;
    return 0;
}
